<!-- Copyright (c) 2022 渝州大数据实验室
 *
 * Lanius is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 -->
<!-- 
* @desc:Layout的左侧组件
* @fileName:Aside.vue
* @author:zoujunjie
* @date:2022-4-7
!-->
<template>
  <div class="aside-container">
    <el-image class="logo" :src="logoUrl" @click="onLogoClick()"></el-image>
    <div class="user-info-container">
      <el-avatar :src="photoUrl" :size="86" />
      <lanius-tooltip :content="user.nickName || user.username">
        <div class="username text-ellipsis">
          {{ user.nickName || user.username }}
        </div>
      </lanius-tooltip>
    </div>
    <aside-menu></aside-menu>
  </div>
</template>

<script lang="ts" setup>
import { useRoute, useRouter } from "vue-router";
import AsideMenu from "./AsideMenu.vue";
import photoUrl from "@/assets/img/layout/default-photo.png";
import localTokenStrategy from "@/common/util/auth";

const logoUrl = new URL(
  "../../../assets/img/layout/logo-white.png",
  import.meta.url
).href;
const router = useRouter();
const route = useRoute();
const user = localTokenStrategy.getUserInfo();
const onLogoClick = (): void => {
  router.push({
    path: route.path.startsWith("/admin") ? "/admin" : "/",
  });
};
</script>

<style lang="scss" scoped>
.aside-container {
  width: 100%;
  min-height: 100%;
  background-color: rgba(56, 65, 102, 1);

  .logo {
    margin-top: 18px;
    margin-left: 26px;
  }
  .logo:hover {
    cursor: pointer;
  }

  .user-info-container {
    margin-top: 22px;
    margin-bottom: 31px;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: white;
    .username {
      margin-top: 20px;
      font-size: 16px;
      max-width: 200px;
    }
  }
}
</style>
